package yawning.mew.bear;

import yawning.mew.sim.SimulationAction;

public class FeralChargeAction implements SimulationAction {
	BearThreatSimulator mState;
	double mCooldownExpireTime = 0.0;

	FeralChargeAction(BearThreatSimulator state) {
		mState = state;

		if (mState.mModel.mToon.getTalent(BearModel.FERALCHARGE) == 0) mCooldownExpireTime = Double.MAX_VALUE;
	}

	@Override
	public double perform() {
		int cost = mState.mModel.feralChargeCost;

		if (mCooldownExpireTime > mState.mSimEngine.getSimTime() || mState.getRage() < cost) return SimulationAction.ACTION_FAIL;

		// If we are in combat we can't Feral Charge.
		if (mState.isInCombat()) {
				return SimulationAction.ACTION_FAIL;
		}

		if (mState.mIsLogging) mState.mLog.log("Feral Charge\n");

		mCooldownExpireTime = mState.mSimEngine.getSimTime() + mState.mModel.feralChargeCDDuration;
		mState.mStampedeEv.onTrigger();

		mNrFeralCharge++;

		mState.onRageLoss(cost, false);

		return 0.0;
	}

	int mNrFeralCharge = 0;
}
